#!/bin/bash

#
# 需要将AuthKey_*.p8文件放到 $HOME/.private_keys目录下
#

#Apple ID if needed
appleid=""
applepassword=""

function uploadIpa() {
    #validate
    /usr/bin/xcrun altool --validate-app -f $1 -t ios --apiKey "$appleid" --apiIssuer "$applepassword"  --verbose

    #upload
    /usr/bin/xcrun altool --upload-app -f $1 -t ios --apiKey "$appleid" --apiIssuer "$applepassword"  --verbose
}

# 查找podspec文件
function find_ipa() {
    current_dir=`pwd`
    ipa_file=`fd ".ipa"`
    if [ ! -n "${ipa_file}" ]; then
        echo
    else
        echo ${current_dir}/${ipa_file}
    fi
}

ipa_file=$(find_ipa)

if [ ! ${ipa_file} ]; then
    echo "not find ipa file."
else
    uploadIpa ${ipa_file}
fi
